package base.tools.controller;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;

import org.springframework.context.annotation.ComponentScan;

import com.hyou.sc.eureka.client.auth.module.user.UserAddController;

/**
 * 这个@ComponentScan注解的basePackageClasses中填写需要生成JUnit代码的Controller类
 * 
 * @author FengChangshuo
 * @version 1.0.0 2018-11-19 14:55:47 初始创建
 */
@ComponentScan(basePackageClasses = {
        UserAddController.class
})
public class ControllerTestCodeMaker {
    
    public void setUp() throws URISyntaxException {
        URI uri = ControllerTestCodeMaker.class.getResource("/").toURI();
        File testClassDir = new File(uri);
        File projectDir = testClassDir.getParentFile().getParentFile();
        File testJavaDir = new File(projectDir, "src/test/java");
        VelocityHandler.setBasePath(testJavaDir.getAbsolutePath());
    }
    
    public void creater() {
        
        ComponentScan componentScan = ControllerTestCodeMaker.class.getAnnotation(ComponentScan.class);
        Class<?>[] classes = componentScan.basePackageClasses();
        
        for (Class<?> controllerClass : classes) {
            try {
                new VelocityHandler(controllerClass).makeTestCodeForClass();
            } catch (Exception e) {
                e.printStackTrace();
            }
            
        }
        
    }
    
    public static void main(String[] args) throws URISyntaxException {
        ControllerTestCodeMaker maker = new ControllerTestCodeMaker();
        maker.setUp();
        maker.creater();
    }
    
}
